package util;

import javax.jms.JMSException;
import javax.jms.ObjectMessage;

import model.ACLMessage;

public class MessageDecryptor {
	public static ACLMessage decryptACLMessage(javax.jms.Message message) throws JMSException {
		ObjectMessage objMsg=decryptJMSMessage(message);
		if(objMsg==null) {
			return null;
		}
		ACLMessage aclMessage = (ACLMessage) objMsg.getObject();
		if(aclMessage instanceof ACLMessage) {
			return aclMessage;
		}
		return null;
	}
	
	public static model.Message decryptUserMessage(javax.jms.Message message) throws JMSException {
		ObjectMessage objMsg=decryptJMSMessage(message);
		if(objMsg==null) {
			return null;
		}
		model.Message userMessage = (model.Message) objMsg.getObject();
		if(userMessage instanceof model.Message) {
			return userMessage;
		}
		return null;
	}
	
	private static ObjectMessage decryptJMSMessage(javax.jms.Message message) {
		if(message==null)
			return null;
		if(message instanceof ObjectMessage) {
			return (ObjectMessage) message;
		}
		return null;
	}
}